﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using PBOffice.BLL;
using PBOffice.Models;

public partial class MeetingRoomManager_AddMeetingRoom : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        this.ddlType.DataSource = new TableTypeManager().GetAllTableType();
        this.ddlType.DataBind();
        //ListItem ll = new ListItem("请选择");
        //this.ddlType.Items.Insert(0, ll);
    }
    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        if (CheckEmpty())
        {
            MeetingRoom room = new MeetingRoom();
            room.RoomNo =txtNo.Text.Trim();
            room.RoomName = this.txtName.Text.Trim();
            TableType type = new TableType();
            type.TypeId = Convert.ToInt32(this.ddlType.SelectedItem.Value);
            type.TypeName = ddlType.SelectedItem.Text;
            room.RoomType = type;
            room.RoomArea = Convert.ToDouble(this.txtArea.Text);
            room.Counts = Convert.ToInt32(this.txtCounts.Text);
            room.Equipment = this.txtEquipment.Text;
            room.RoomImge = Server.MapPath("../UploadPic")+"\\" + fuRoomImge.FileName;
            fuRoomImge.SaveAs(room.RoomImge);
            new MeetingRoomManager().AddMeetingRoom(room);
        }
    }
    private bool CheckEmpty()
    {

        if (this.txtNo.Text == "")
        {
            Page.ClientScript.RegisterClientScriptBlock(typeof(string), "alert", "<script>alert('会议室编号不能为空！')</script>");
            return false;
        }

        if (this.txtName.Text == "")
        {
            Page.ClientScript.RegisterClientScriptBlock(typeof(string), "alert", "<script>alert('会议室名称不能为空！')</script>");
            return false;
        }
        if (this.txtArea.Text == "")
        {
            Page.ClientScript.RegisterClientScriptBlock(typeof(string), "alert", "<script>alert('使用面积不能为空！')</script>");
            return false;
        }
        if (this.txtCounts.Text == "")
        {
            Page.ClientScript.RegisterClientScriptBlock(typeof(string), "alert", "<script>alert('容纳人数不能为空！')</script>");
            return false;
        }
        if (this.txtEquipment.Text == "")
        {
            Page.ClientScript.RegisterClientScriptBlock(typeof(string), "alert", "<script>alert('办公设备不能为空~')</script>");
            return false;
        }
        //if (this.ddlType.SelectedItem.Text == "请选择")
        //{
        //    Page.ClientScript.RegisterClientScriptBlock(typeof(string), "alert", "<script>alert('您还没有选择类型！')</script>");
        //    return false;
        //}
        if (this.fuRoomImge.FileName == "")
        {
            Page.ClientScript.RegisterClientScriptBlock(typeof(string), "alert", "<script>alert('您还没有上传会议室图片！')</script>");
            return false;
        }
        return true;
    }
}